﻿using System;
using System.Linq;
using System.ComponentModel.DataAnnotations;

namespace TaoNiuOA.Models
{
    /// <summary>
    /// 考勤实体
    /// </summary>
    public class Checking
    {
        [Key]
        public int ChenkingID { get; set; }

        [Display(Name = "用户ID")]
        public int UserID { get; set; }

        [Display(Name = "日期")]
        public string Date { get; set; }

        private string onWork;
        [Display(Name = "上班签到时间")]
        public string OnWork
        {
            get { return this.onWork ?? "未登记"; }
            set { onWork = value; }
        }

        private string offWork;
        [Display(Name = "下班签到时间")]
        public string OffWork
        {
            get { return this.offWork ?? "未登记"; }
            set { offWork = value; }
        }

        [Display(Name = "是否请假")]
        public bool? IsLeave { get; set; }

        [Display(Name = "备注")]
        public string Remark { get; set; }

        public Checking()
        {
        }

        /// <summary>
        /// 该任务的负责人信息
        /// </summary>
        /// <returns></returns>
        public User GetUser()
        {
            var db = new TaoNiuOA.Models.DbEntity();
            var u = db.Users.SingleOrDefault(n => n.UserID == this.UserID);
            if (u == null)
            {
                u = new User();
                u.UserID = 0;
                u.UserName = "未定义";
            }
            return u;
        }
    }
}